package com.lucifer.hawkeye.ai.api;

import com.lucifer.hawkeye.ai.common.response.RestResult;
import com.lucifer.hawkeye.ai.service.RagService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author lucifer
 * @date 2025/4/1 16:10
 */
@RestController
@RequestMapping("/rag")
public class RagApi {

    @Resource
    private RagService ragService;

    @PostMapping("/write")
    public RestResult write(
            @RequestParam("file") MultipartFile file) {
        return RestResult.buildSuccessResult(ragService.write(file));
    }


    @PostMapping("/search")
    public RestResult search(
            @RequestParam(value = "conversationId") String conversationId,
            @RequestParam(value = "ragType") String ragType,
            @RequestParam(value = "content") String content,
            @RequestParam(value = "tableName", required = false) String tableName) {
        return ragService.search(conversationId, ragType, content, tableName);
    }
}
